package com.logic.landseaserver.ws;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import com.logic.landseaserver.service.*;
import com.logic.landseaserver.ws.dto.LocalSignDTOTest;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.logic.common.enums.HttpCodeEnum;
import com.logic.common.exception.BusinessException;
import com.logic.common.util.CommonResult;
import com.logic.common.util.CommonResultMap;
import com.logic.common.util.QueryUtil;
import com.logic.landseaserver.common.LandeaConstants;
import com.logic.landseaserver.common.LandeaConstants.ReRentType;
import com.logic.landseaserver.common.enums.BTypeEnum;
import com.logic.landseaserver.common.enums.BillStatusEnum;
import com.logic.landseaserver.common.enums.DepositEnum;
import com.logic.landseaserver.common.exception.LandseaBusinessException;
import com.logic.landseaserver.common.exception.LandseaException;
import com.logic.landseaserver.domain.Bill;
import com.logic.landseaserver.domain.Contract;
import com.logic.landseaserver.domain.Deposit;
import com.logic.landseaserver.domain.VerificationCode;
import com.logic.landseaserver.models.changeroom.service.ChangeRoomService;
import com.logic.landseaserver.models.prepayment.service.AutoPayBillService;
import com.logic.landseaserver.models.prepayment.service.PrepaymentService;
import com.logic.landseaserver.models.rerent.service.IReRentService;
import com.logic.landseaserver.persistence.read.ContractReadMapper;
import com.logic.landseaserver.persistence.write.ContractWriteMapper;
import com.logic.landseaserver.service.impl.SendMsgServiceImpl;
import com.logic.landseaserver.ws.dto.ContractPdfDTO;
import com.logic.landseaserver.ws.dto.DepositDTO;
import com.logic.landseaserver.ws.dto.LocalSignDTO;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@Path("/contract")
@Api(value = "线下合同Controller")
public class ContractRest {
    @Autowired
    private IContractService contractService;
    @Autowired
    private ContractReadMapper contractReadMapper;
    @Autowired
    private ContractWriteMapper contractWriteMapper;
    
    @Autowired
    private ILsLocalSignService lsLocalSignServiceImpl;
    
    @Autowired
    private SendMsgServiceImpl sendMsgServiceImpl;
    
    @Autowired
    private IBillService billService;
    
    @Autowired
    private IDepositService depositService;
    
    @Autowired
    private AutoPayBillService autoPayBillService;

    @Autowired
    private IReRentService reRentService;

    @Autowired
    private ICheckFeeListService checkFeeListService;
    
    @Autowired
    private ChangeRoomService changeRoomService;
    
    @Autowired
    private PrepaymentService prepaymentService;

    @Autowired
    private ICustomerCardService customerCardService;
    
    private static final Logger logger = LoggerFactory.getLogger(ContractRest.class);
    
    
    @POST
    @Path("/admin/list")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    @ApiOperation(value = "Retrieve contract list.", position = 4)
    public Response queryContracts(@ApiParam(value = "param", required = true) QueryUtil queryUtil) {
        CommonResultMap map = new CommonResultMap();
        List<?> contractList = null;
        try {
            queryUtil.getPagingTool().calculateStartIndex();
            contractList = contractService.queryContractList(queryUtil);
            Integer totalCount = queryUtil.getPagingTool().getTotalNum();
            map.setData(contractList);
            map.setResultTotalCount(totalCount);
            map.setResult(CommonResult.SUCCESS);
        } catch (Exception e) {
            logger.error("queryContracts error.", e);
            map.setResult(CommonResult.ERROR, e.getMessage());
        }
        return Response.status(HttpCodeEnum.OK.getCode()).entity(map).build();
    }
    
    @GET
    @Path("/admin/{id}")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    @ApiOperation(value = "query detail contract by id", position = 4)
    public Response getContract(
        @ApiParam(value = "param", required = true) @PathParam("id") Integer id) {
        CommonResultMap map = new CommonResultMap();
        try {
            map.setData(contractService.get(id));
            map.setResult(CommonResult.SUCCESS, "pay success");
        } catch (Exception e) {
            logger.error("getContract error.", e);
            map.setResult(CommonResult.ERROR, e.getMessage());
        }
        return Response.status(HttpCodeEnum.OK.getCode()).entity(map).build();
    }
    
    @DELETE
    @Path("/deleted/{minutes}")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    @ApiOperation(value = "query detail contract by id", position = 4)
    public Response delete(
        @ApiParam(value = "param", required = true) @PathParam("minutes") Integer minutes) {
        CommonResultMap map = new CommonResultMap();
        try {
            contractService.deleteContractList(minutes);
            map.setResult(CommonResult.SUCCESS, "pay success");
        } catch (Exception e) {
            logger.error("delete contract error.", e);
            map.setResult(CommonResult.ERROR, e.getMessage());
        }
        return Response.status(HttpCodeEnum.OK.getCode()).entity(map).build();
    }
    
    @DELETE
    @Path("/{id}")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    @ApiOperation(value = "query detail contract by id", position = 4)
    public Response deleteById(
        @ApiParam(value = "param", required = true) @PathParam("id") Integer id) {
        CommonResultMap map = new CommonResultMap();
        try {
            contractService.deleteById(id);
            
            map.setResult(CommonResult.SUCCESS, "pay success");
        } catch (Exception e) {
            logger.error("delete contract error.", e);
            map.setResult(CommonResult.ERROR, e.getMessage());
        }
        return Response.status(HttpCodeEnum.OK.getCode()).entity(map).build();
    }
    
    @PUT
    @Path("/getContractPdfInfo")
    @Produces(MediaType.APPLICATION_JSON)
    @ApiOperation(value = "合同pdf信息接口", position = 12)
    public Response getContractPdfInfo(
        @ApiParam(value = "param", required = true) @QueryParam("id") int id) {
        CommonResultMap map = new CommonResultMap();
        ContractPdfDTO obj = null;
        try {
            obj = contractService.getContractPdfDTO(id);
            map.setData(obj);
            map.setResult(CommonResult.SUCCESS);
        } catch (Exception e) {
            logger.error("getContractPdfInfo error.", e);
            map.setResult(CommonResult.ERROR, e.getMessage());
        }
        return Response.status(HttpCodeEnum.OK.getCode()).entity(map).build();
    }
    
    @PUT
    @Path("/productContractPdf")
    @Produces(MediaType.APPLICATION_JSON)
    @ApiOperation(value = "生成合同pdf", position = 12)
    public Response productContractPdf(
        @ApiParam(value = "param", required = true) @QueryParam("id") int id) {
        CommonResultMap map = new CommonResultMap();
        Integer fileid = null;
        try {
            fileid = contractService.productContractPdf(id,LandeaConstants.PdfOprType.ADD_UPDATE);
            HashMap resultmap = new HashMap();
            resultmap.put("fileId", fileid);
            map.setData(resultmap);
            map.setResult(CommonResult.SUCCESS);
        } catch (Exception e) {
            logger.error("productContractPdf error.", e);
            map.setResult(CommonResult.ERROR, e.getMessage());
        }
        return Response.status(HttpCodeEnum.OK.getCode()).entity(map).build();
    }
    
    @GET
    @Path("/createPDF")
    @Produces(MediaType.APPLICATION_JSON)
    @ApiOperation(value = "生成合同pdf", position = 12)
    public Response createPDF() {
        CommonResultMap map = new CommonResultMap();
        List<Integer> ids;
        try {
            ids = contractReadMapper.queryPdf();
            Contract contract = new Contract();
            for (int i = 0; ids.size() > 0 && i <= ids.size(); i++) {
                try {
                    Integer pdfId = contractService.productContractPdf(ids.get(i),LandeaConstants.PdfOprType.ADD_UPDATE);
                    if (pdfId != null) {
                        contract.setId(ids.get(i));
                        contract.setPdfId(pdfId);
                        contract.updateCommonInfo(-1);
                        contractWriteMapper.updateByPrimaryKeySelective(contract);
                    }
                } catch (Exception e) {
                    
                }
            }
            map.setResult(CommonResult.SUCCESS);
        } catch (Exception e) {
            logger.error("createPDF error.", e);
            map.setResult(CommonResult.ERROR, e.getMessage());
        }
        return Response.status(HttpCodeEnum.OK.getCode()).entity(map).build();
    }
    
    @POST
    @Path("/localSign")
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    @ApiOperation(value = "local sign")
    public Response localSign(@ApiParam(value = "param", required = true) LocalSignDTO localSignDTO) {
        CommonResultMap map = new CommonResultMap();
        try {
            Map<String, String> pathMap = new HashMap<String, String>();
            String path = lsLocalSignServiceImpl.localSign(localSignDTO);
            pathMap.put("remotePath", path);
            //发送短信
            // 需要推送消息Tony(P4需要做的)
            if(localSignDTO.getContractId()!=null){
                //获取首付款的账单ID
                Bill bill = billService.queryFirstBill(localSignDTO.getContractId());
                Contract contract = contractReadMapper.selectByPrimaryKey(localSignDTO.getContractId());;
                //如果首期账单已付  则需变更文件名
                if(bill.getBillStatus().equals(BillStatusEnum.BIST2.getCode())){
                    Contract reSignContract = new Contract();
                    reSignContract.setId(localSignDTO.getContractId());
                    contractService.renameContractPdf(reSignContract);
                }else{
                    //如果是首期款没有支付则默认为第一次签字
                    /*  sendMsgServiceImpl.sendMessage(localSignDTO.getContractId(), BTypeEnum._BT1.getCode(),bill.getId());
                    if(contract.getOriginalCId()!=null && contract.getRentType().equals(ReRentType.RERENT)){
                        reRentService.synOverList(contract.getId());
                        checkFeeListService.synFeeList(localSignDTO.getContractId());
                        // 合同签字成功生成对应的账户 自动抵扣账单,只有续租合同且签过字才抵扣
                        autoPayBillService.autoPayByUserRoom(contract.getUserId(), contract.getRoomId());
                    }*/
                }
            }
            if(localSignDTO.getDepositId()!=null){
                DepositDTO depositDTO = (DepositDTO)depositService.get(localSignDTO.getDepositId());
                //不为草稿则需变更文件名称
                if(!depositDTO.getStatus().equals(DepositEnum._DS1.getCode())){
                    Deposit deposit = new Deposit();
                    deposit.setId(localSignDTO.getDepositId());
                    depositService.renamePDF(deposit);
                }
            }
            map.setResult(CommonResult.SUCCESS, "签字成功");
        } catch (BusinessException e) {
            logger.error("local sign  LandseaBusinessException", e);
            map.setResult(CommonResult.BUSINESS_EXCEPTION, e.getMessage());
        }catch (Exception e) {
            logger.error("local sign failure", e);
            map.setResult(CommonResult.ERROR, e.getMessage());
        }
        return Response.status(HttpCodeEnum.OK.getCode()).entity(map).build();
    }
    
    @POST
    @Path("/localSignConfirmation")
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    @ApiOperation(value = "local sign")
    public Response localSignConfirmation(@ApiParam(value = "param", required = true) VerificationCode verificationcode) {
        CommonResultMap map = new CommonResultMap();
        try {
            
            HashMap<String, Object> map2 = lsLocalSignServiceImpl.localSignConfirmation(verificationcode);
            map.setData(map2);
        } catch (BusinessException e) {
            logger.error("BusinessException", e);
            map.setResult(e);
        } catch (Exception e) {
            logger.error("local sign failure", e);
            map.setResult(CommonResult.ERROR, e.getMessage());
        }
        return Response.status(HttpCodeEnum.OK.getCode()).entity(map).build();
    }
    
    
    @POST
    @Path("/user/getMyContracts")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    @ApiOperation(value = "获得个人合同", position = 12)
    public Response getMyContracts(@ApiParam(value = "param", required = true) QueryUtil queryUtil) {
        CommonResultMap map = new CommonResultMap();
        try {
            map.setData(contractService.getMyContracts(queryUtil));
            map.setResult(CommonResult.SUCCESS);
        } catch (BusinessException e) {
            logger.error("getMyContracts error.", e);
            map.setResult(CommonResult.BUSINESS_EXCEPTION, e.getMessage());
        } catch (Exception e) {
            logger.error("getMyContracts error.", e);
            map.setResult(CommonResult.ERROR, e.getMessage());
        }
        return Response.status(HttpCodeEnum.OK.getCode()).entity(map).build();
    }
    
    @GET
    @Path("/user/getMyContracts/{id}")
    @Produces(MediaType.APPLICATION_JSON)
    @ApiOperation(value = "获得个人合同详情", position = 12)
    public Response getMyContractsById(
        @ApiParam(value = "param", required = true) @PathParam("id") Integer id) {
        CommonResultMap map = new CommonResultMap();
        try {
            map.setData(contractService.getMyContractsById(id));
            map.setResult(CommonResult.SUCCESS);
        } catch (BusinessException e) {
            logger.error("getMyContractsById error.", e);
            map.setResult(CommonResult.BUSINESS_EXCEPTION, e.getMessage());
        } catch (Exception e) {
            logger.error("getMyContractsById error.", e);
            map.setResult(CommonResult.ERROR, e.getMessage());
        }
        return Response.status(HttpCodeEnum.OK.getCode()).entity(map).build();
    }
    
    @POST
    @Path("/testCreatePDFImg")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    @ApiOperation(value = "测试生成PDF对应的图片", position = 8)
    public Response testCreatePDFImg()
    {
        CommonResultMap map = new CommonResultMap();
        Map<String, Object> result = new HashMap<String, Object>();
        try
        {
            contractService.testCreatePDFImg();
            result.put("STATUS", 0);
            map.setData(result);
        }
        catch (Exception e)
        {
            logger.info("testCreatePDFImg Exception" + e.getMessage());
            map.setResult(CommonResult.BUSINESS_EXCEPTION, e.getMessage());
        }
        return Response.status(HttpCodeEnum.OK.getCode()).entity(map).build();
    }
    
    @PUT
    @Path("/updateVersion/{id}")
    @Produces(MediaType.APPLICATION_JSON)
    @ApiOperation(value = "合同变更重新生成PDF文件", position = 13)
    public Response updateVersion( @ApiParam(value = "param", required = true) @PathParam("id") Integer id) {
        CommonResultMap map = new CommonResultMap();
        try {
            contractService.updateVersion(id);
            map.setResult(CommonResult.SUCCESS);
        }  catch (LandseaBusinessException e) {
            logger.error("updateVersion LandseaBusinessException.", e);
            map.setResult(CommonResult.BUSINESS_EXCEPTION, e.getMessage());
        }catch (Exception e) {
            logger.error("updateVersion error.", e);
            map.setResult(CommonResult.ERROR, e.getMessage());
        }
        return Response.status(HttpCodeEnum.OK.getCode()).entity(map).build();
    }
    
    @GET
    @Path("/getVersions/{id}")
    @Produces(MediaType.APPLICATION_JSON)
    @ApiOperation(value = "获得合同历史变更记录", position = 14)
    public Response queryHistoryVersions(
        @ApiParam(value = "param", required = true) @PathParam("id") Integer id) {
        CommonResultMap map = new CommonResultMap();
        try {
            map.setData(contractService.queryHistoryVersions(id));
            map.setResult(CommonResult.SUCCESS);
        } catch (BusinessException e) {
            logger.error("queryHistoryVersions error.", e);
            map.setResult(CommonResult.BUSINESS_EXCEPTION, e.getMessage());
        } catch (Exception e) {
            logger.error("queryHistoryVersions error.", e);
            map.setResult(CommonResult.ERROR, e.getMessage());
        }
        return Response.status(HttpCodeEnum.OK.getCode()).entity(map).build();
    }
    
    @POST
    @Path("/getChangeVersionCount")
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    @ApiOperation(value = "获得合同历史变更记录的总数", position = 14)
    public Response getChangeVersionCount( @ApiParam(value = "param", required = true) Map pmap) {
        CommonResultMap map = new CommonResultMap();
        try {
            String prjId =  (String)pmap.get("prjId");
            HashMap resultMap = new HashMap();
            if(StringUtils.isEmpty(prjId)){
                resultMap.put("count",contractService.getChangeVersionCount(null));
            }else{
                resultMap.put("count",contractService.getChangeVersionCount(Integer.parseInt(prjId)));
            }
            map.setData(resultMap);
            map.setResult(CommonResult.SUCCESS);
        }catch (Exception e) {
            logger.error("queryHistoryVersions error.", e);
            map.setResult(CommonResult.ERROR, e.getMessage());
        }
        return Response.status(HttpCodeEnum.OK.getCode()).entity(map).build();
    }

    @POST
    @Path("/getChangeRoomCount")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    @ApiOperation(value = "获得合同换房记录的总数")
    public Response getChangeRoomCount(@ApiParam(value = "param", required = true) Map<String, Object> requestMap)
    {
        CommonResultMap map = new CommonResultMap();
        try
        {
            Map<String, Object> result = changeRoomService.getChangeRoomCount(requestMap);
            map.setData(result);
            map.setResult(CommonResult.SUCCESS);
        }catch (Exception e) {
            logger.error("getChangeRoomCount error.", e);
            map.setResult(CommonResult.ERROR, e.getMessage());
        }
        return Response.status(HttpCodeEnum.OK.getCode()).entity(map).build();
    }
    
    @PUT
    @Path("/testUpdateContractEnd")
    @Produces(MediaType.APPLICATION_JSON)
    @ApiOperation(value = "测试结束续租原合同", position = 12)
    public Response testUpdateContractEnd(
            @ApiParam(value = "param", required = true) @QueryParam("inDate") String inDate) {
        CommonResultMap map = new CommonResultMap();
        try {
            contractService.updateContractEnd(inDate);
            map.setResult(CommonResult.SUCCESS);
        } catch (Exception e) {
            logger.error("testUpdateContractEnd error.", e);
            map.setResult(CommonResult.ERROR, e.getMessage());
        }
        return Response.status(HttpCodeEnum.OK.getCode()).entity(map).build();
    }

    @POST
    @Path("/afterFirstlocalSign/{contractId}")
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    @ApiOperation(value = "local sign")
    public Response afterFirstlocalSign(@ApiParam(value = "param", required = true) @PathParam("contractId") Integer contractId) {
        CommonResultMap map = new CommonResultMap();
        try {
            if(contractId!=null) {
                Contract contract = contractReadMapper.selectByPrimaryKey(contractId);
                if(contract!=null){
                    //获取首付款的账单ID
                    Bill bill = billService.queryFirstBill(contractId);
                    //如果首期账单未支付 部分支付
                    if (!bill.getBillStatus().equals(BillStatusEnum.BIST2.getCode())) {
                        sendMsgServiceImpl.sendMessage(contractId, BTypeEnum._BT1.getCode(), bill.getId());
                        //续租合同处理
                        if (contract.getOriginalCId() != null && contract.getRentType().equals(ReRentType.RERENT)) {
                            reRentService.synOverList(contractId);
                            //同步交割单信息
                            checkFeeListService.synFeeList(contractId);
                            //同步checkFees 至 运营数据表
                            checkFeeListService.sysFeeListToExpenses(contractId, LandeaConstants.CheckType.UN_RENT);
                            // 合同签字成功生成对应的账户 自动抵扣账单,只有续租合同且签过字才抵扣
                            logger.info("续租首期签字后，开始自动抵扣账单.userId=" + contract.getUserId());
                            autoPayBillService.autoPayByUserRoom(contract.getUserId(), contract.getRoomId());
                        }
                        //转租合同处理
                        if (contract.getOriginalCId() != null && contract.getRentType().equals(ReRentType.CHANGE)) {
                            checkFeeListService.synFeeList(contractId);
                            checkFeeListService.sysFeeListToExpenses(contractId, LandeaConstants.CheckType.UN_RENT);
                        }
                        // 换房
                        if (contract.getOriginalCId() != null && contract.getRentType().equals(ReRentType.TURN)) {
                            // 处理AB账单、生成B账户
                            changeRoomService.synOverList(contractId);
                            // 将A账户的余额转到B账户去
                            prepaymentService.changeRoomAccountProcess(contract, contract.getOriginalCId());
                            // B账户自动抵扣账单
                            autoPayBillService.autoPayByUserRoom(contract.getUserId(), contract.getRoomId());
                        }
                    }
                    map.setResult(CommonResult.SUCCESS);
                }
            }
        } catch (LandseaException ex) {
            logger.error("afterFirstlocalSign LandseaException", ex);
            map.setResult(CommonResult.SUCCESS, ex.getMessage());
        } catch (Exception e) {
            logger.error("afterFirstlocalSign Exception", e);
            map.setResult(CommonResult.ERROR, e.getMessage());
        }
        return Response.status(HttpCodeEnum.OK.getCode()).entity(map).build();
    }

    @POST
    @Path("/getChangeRentCount")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    @ApiOperation(value = "获得已转租待处理合同记录的总数", position = 14)
    public Response getChangeRentCount( @ApiParam(value = "param", required = true) Map pmap) {
        CommonResultMap map = new CommonResultMap();
        try {
            String prjId =  (String)pmap.get("prjId");
            HashMap resultMap = new HashMap();
            if(StringUtils.isEmpty(prjId)){
                resultMap.put("count",contractService.getChangeRentCount(null));
            }else{
                resultMap.put("count",contractService.getChangeRentCount(Integer.parseInt(prjId)));
            }
            map.setData(resultMap);
            map.setResult(CommonResult.SUCCESS);
        }catch (Exception e) {
            logger.error("getChangeRentCount error.", e);
            map.setResult(CommonResult.ERROR, e.getMessage());
        }
        return Response.status(HttpCodeEnum.OK.getCode()).entity(map).build();
    }


    @PUT
    @Path("/testClearChangeRoom")
    @Produces(MediaType.APPLICATION_JSON)
    @ApiOperation(value = "测试超时取消换房 传参格式为%Y-%m-%d %H", position = 14)
    public Response testCancleChangeRoom(
            @ApiParam(value = "param", required = true) @QueryParam("changeDate") String changeDate) {
        CommonResultMap map = new CommonResultMap();
        try {
            changeRoomService.clearOverTimeCRRecord(changeDate);
            map.setResult(CommonResult.SUCCESS);
        }catch (Exception e) {
            logger.error("testClearChangeRoom error.", e);
            map.setResult(CommonResult.ERROR, e.getMessage());
        }
        return Response.status(HttpCodeEnum.OK.getCode()).entity(map).build();
    }

    @POST
    @Path("/testLocalSign")
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    @ApiOperation(value = " test local sign")
    public Response testLocalSign(@ApiParam(value = "param", required = true) LocalSignDTOTest localSignDTO) {
        CommonResultMap map = new CommonResultMap();
        try {
             lsLocalSignServiceImpl.testLocalSign(localSignDTO);
            map.setResult(CommonResult.SUCCESS, "test签字成功");
        } catch (BusinessException e) {
            logger.error("testLocalSign  LandseaBusinessException", e);
            map.setResult(CommonResult.BUSINESS_EXCEPTION, e.getMessage());
        }catch (Exception e) {
            logger.error("testLocalSign failure", e);
            map.setResult(CommonResult.ERROR, e.getMessage());
        }
        return Response.status(HttpCodeEnum.OK.getCode()).entity(map).build();
    }

    @GET
    @Path("/queryCardInfo/{id}")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    @ApiOperation(value = "query detail customer card info by contract id", position = 12)
    public Response queryCardInfo(
            @ApiParam(value = "param", required = true) @PathParam("id") Integer id) {
        CommonResultMap map = new CommonResultMap();
        try {
            HashMap queryMap= new HashMap();
            queryMap.put("mainId",id);
            queryMap.put("mainType",LandeaConstants.QueryUesdCodeType.CONTRACT);
            map.setData(customerCardService.queryCardInfo(queryMap));
            map.setResult(CommonResult.SUCCESS, "queryCardInfo success");
        } catch (Exception e) {
            logger.error("queryCardInfo error.", e);
            map.setResult(CommonResult.ERROR, e.getMessage());
        }
        return Response.status(HttpCodeEnum.OK.getCode()).entity(map).build();
    }


}

